package com.edu.labmanager.service.impl;


import com.edu.labmanager.entity.Email;
import com.edu.labmanager.service.IEmailService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQListener {
    @Autowired
    private IEmailService emailService;

    @RabbitListener(messageConverter = "jsonMessageConverter",bindings = @QueueBinding(
            value = @Queue(name = "email_Queuse"),
            exchange = @Exchange(name ="exchange", type = ExchangeTypes.DIRECT),
            key = {"email"}
    ))
    public void listenDirectQueue2(Email email){
        System.out.println(email);
        emailService.save(email);
    }
}